<?php 

function connettidb(){
	
	include 'config.php';
		
	mysql_connect($db['host'],$db['userdb'],$db['password'])
	or die('impossibile collegarsi al server');
	
	mysql_select_db($db['nomedb'])
	or die ('impossibile collegarsi al database');
} 

function getPage($id, $lang='it')
{
connettiDb();
$sql="SELECT id, section, 
					sub_section, 
					status, title_$lang as title, 
					content_$lang as content
		FROM pages 
		WHERE id=$id AND status=1";
	
	$result=mysql_query($sql);
	//$content=mysql_fetch_assoc($result);	
	return $result;
	//echo $content['title'];
	
}
function getAllPages ($lang= 'it')
{
connettiDb();
$sql="SELECT id, section, 
					sub_section, 
					status, title_$lang as title, 
					content_$lang as content
		FROM pages 
		WHERE status=1
		ORDER BY title";
	
	$result=mysql_query($sql);
	return $result;		
}
function getAllPagesBySection($section, $lang= 'it')
{
connettiDb();
$sql="SELECT id, section, 
					sub_section, 
					status, title_$lang as title, 
					content_$lang as content
		FROM pages 
		WHERE status=1 AND section ='$section'
		ORDER BY sub_section, title";
	//echo $sql;
	$result=mysql_query($sql);
	return $result;		
}
function getAllPagesBySubSection($section, $subsection, $lang= 'it')
{
connettiDb();
$sql="SELECT id, section, 
					sub_section, 
					status, title_$lang as title, 
					content_$lang as content
		FROM pages 
		WHERE status=1 AND section =$section AND sub_section = $subsection
		ORDER BY sub_section, title";
	
	$result=mysql_query($sql);
	return $result;		
}
function isCorrectSection($request)
{
	require_once'config.php';
	return isset($sections[$request]);
}

function t($word, $lang = 'it')
{
	include 'words.php';
	if(!isset($words[$lang]))
	{
		$lang='it';
	} 
	if(!isset($words[$lang][$word]))
	{
		$word= 'default';
	}
	return $words[$lang][$word];
}

?>